package hlhj.fhp.checkpoint.http

import com.lzy.okgo.OkGo
import com.lzy.okgo.model.HttpParams
import com.lzy.okgo.model.Response
import com.lzy.okrx2.adapter.ObservableResponse
import io.reactivex.Observable
import io.reactivex.schedulers.Schedulers

/**
 * Created by Never Fear   on 2018\11\14 0014.
Never More....
 */
object OkHelper {
    var GET=1
    var POST=2
    fun <T>createRequest (httpParams: HttpParams,way:Int,url:String): Observable<Response<T>>? {
        if (way==1){
            val getRequest = OkGo.get<T>(url)
          return  getRequest
                  .converter(object :MyJsonConvert<T>(){})
                  .params(httpParams)
                    .adapt(ObservableResponse<T>())
                    .subscribeOn(Schedulers.io())
        }else{
            val postRequest = OkGo.post<T>(url)
            return  postRequest.converter(object :MyJsonConvert<T>(){})
                    .params(httpParams)

                    .adapt(ObservableResponse<T>())
                    .subscribeOn(Schedulers.io())
        }
    }
}